package config

import (
	"github.com/go-redis/redis/v8"
	"github.com/jinzhu/gorm"
	"github.com/joho/godotenv"
	"log"
)

func Init() {
	err := godotenv.Load()
	if err != nil {
		log.Fatalf("Error loading .env file: %s", err)
	}
	InitMysql()
	InitRedis()
}

func Close() {
	defer func(Mysql *gorm.DB) {
		err := Mysql.Close()
		if err != nil {
			log.Fatalf("Error Close Mysql: %s", err)
		}
	}(Mysql)

	defer func(Rdb *redis.Client) {
		err := Rdb.Close()
		if err != nil {
			log.Fatalf("Error Close Redis: %s", err)
		}
	}(Rdb)
}
